package com.example.weiting.huishenghuo.utils;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.weiting.huishenghuo.R;

import java.util.List;


public class MessageAdapter extends ArrayAdapter {
    private final int resourceId;
    public MessageAdapter(Context context, int textViewResourceId, List<Message> objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Message message = (Message) getItem(position); // 获取当前项的Message实例
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);//实例化一个对象

        TextView messageName = (TextView) view.findViewById(R.id.textView5);//获取该布局内的文本视图
        TextView messageName1 = (TextView) view.findViewById(R.id.textView7);
        TextView messageName2 = (TextView) view.findViewById(R.id.textView6);
        messageName.setText(message.getThing());
        messageName1.setText(message.getDate().toString());
        if (message.getZhuangTai() > 0 ) {
            messageName2.setText("+" + String.valueOf(message.getZhuangTai()));
        }
        else {
            messageName2.setTextColor(Color.rgb(255, 0, 0));
            messageName2.setText(String.valueOf(message.getZhuangTai()));
        }
        return view;
    }

}
